import sys

from PyQt5.QtWidgets import QMainWindow, QVBoxLayout, QHBoxLayout, QTextEdit, QWidget, QPushButton, QApplication, QLabel


# インターフェース

class BoxJan(QMainWindow):
    def __init__(self, parents=None):
        super(BoxJan, self).__init__(parents)
        self.setWindowTitle('GBKからshift-jis')
        self.resize(300, 90)

        self.jis_label=QLabel('乱\n码\n文\n本')
        self.gbk_label=QLabel('正\n常\n文\n本')

        self.layout_gbk = QHBoxLayout()

        self.gbk_text = QTextEdit()
        self.gbk_text.setText('嬚梩巓枀偲儔僀僒儞僩搰偺揱愢')
        self.gbk_to_shift = QPushButton()
        self.gbk_to_shift.setText('解码')
        self.gbk_to_shift.clicked.connect(self.gbk)
        self.layout_gbk.addWidget(self.jis_label)
        self.layout_gbk.addWidget(self.gbk_text)
        self.layout_gbk.addWidget(self.gbk_to_shift)
        self.gbk_weight = QWidget()
        self.gbk_weight.setLayout(self.layout_gbk)

        self.layout_jis = QHBoxLayout()
        self.jis_text = QTextEdit()
        self.jis_to_gbk = QPushButton()
        self.jis_to_gbk.setText('转码')
        self.jis_to_gbk.clicked.connect(self.jis)
        self.jis_weight = QWidget()
        self.layout_jis.addWidget(self.gbk_label)
        self.layout_jis.addWidget(self.jis_text)
        self.layout_jis.addWidget(self.jis_to_gbk)
        self.jis_weight = QWidget()
        self.jis_weight.setLayout(self.layout_jis)

        self.main_layout=QVBoxLayout()
        self.main_layout.addWidget(self.gbk_weight)
        self.main_layout.addWidget(self.jis_weight)

        # self.setLayout(self.main_layout)
        total_weight=QWidget()
        total_weight.setLayout(self.main_layout)
        self.setCentralWidget(total_weight)

    def gbk(self):
        gbk_mess=self.gbk_text.toPlainText()
        # print(gbk_mess)
        self.trans(gbk_mess)

    def jis(self):
        pass

    def trans(self,gbk_t:str):
        self.jis_text.setText(gbk_t.encode('gbk').decode('shift-jis'))


if __name__ == '__main__':
    app = QApplication(sys.argv)
    show = BoxJan()
    show.show()
    sys.exit(app.exec_())
